<template>
  <view>
    <view class="search-box">
      <my-search :background="'#C00000'" :redus="20" @click='gotoSearch()'></my-search>
    </view>
    
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000":circular="true">
      <swiper-item v-for="(item,index) in swiperList" :key=index>
        <navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id">
          <image :src="item.image_src" mode=""></image>
        </navigator>
      </swiper-item>
    </swiper>
    
    <view class="nav-list" >
      <view @click="navClickHandler(item)" class="nav-item" v-for="(item,index) in navList" :key="index">
        <image :src="item.image_src" class="nav-image"></image>
      </view>
    </view>
    
    <view class="foor-list">
      <view class="foor-item" v-for="(item,index) in foorList" :key="index">
        <image :src="item.floor_title.image_src" class="foor-image"></image>
        
        <view class="foor-box">
        <navigator class="foor-left-box" :url="item.product_list[0].url">
          <image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
        </navigator>
        <view class="foor-right-box">
          <navigator :url="item2.url" class="foor-right-box-item" v-for="(item2,i2) in item.product_list" :key='i2' v-if="i2 !== 0">
            <image :src="item2.image_src" :style="{width: item2.image_width+'rpx'}" mode="widthFix"></image>       
          </navigator>
        </view>
      </view>
      </view>
    </view>
  </view>
</template>

<script>
  // 导入自己封装的 mixin 模块
  import badgeMix from '@/mixins/tabbar-badge.js'
  
export default {
    // 将 badgeMix 混入到当前的页面中进行使用
    mixins: [badgeMix],
    data() {
      return {
        swiperList:[],
        navList:[],
        foorList:[],
      }
    },
    onLoad(){
      this.getSwiperList(),
      this.getNavList(),
      this.getFoorList()
    },
    methods:{
      async getSwiperList(){
        // 发起数据请求
         const {data:res} = await uni.$http.get('/api/public/v1/home/swiperdata')
        // 请求失败
        if(res.meta.status != 200)   return  uni.$showMsg()
        this.swiperList = res.message
      },
      async getNavList(){
        // 发起数据请求
         const {data:res} = await uni.$http.get('/api/public/v1/home/catitems')
        // 请求失败
        if(res.meta.status != 200)   return  uni.$showMsg()
        this.navList = res.message
      },
      async getFoorList(){
        // 发起数据请求
         const {data:res} = await uni.$http.get('/api/public/v1/home/floordata')
        // 请求失败
        if(res.meta.status != 200)   return  uni.$showMsg()
        // 导航路由的凭借
        res.message.forEach(floor=>{
          floor.product_list.forEach(prod=>{
            prod.url = '/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1]
          })
        })
        console.log(res.message)
        this.foorList = res.message
      },
      navClickHandler(item){
        console.log(item)
        if (item.name === '分类'){
          uni.switchTab({
            url:'../cate/cate'
          })
        }
      },
      gotoSearch(){
        uni.navigateTo({
          url:'/subpkg/search/search'
        })
      }
    }
  }
</script>
<style lang="scss">
swiper{
  height: 330rpx;
  .swiper-item,
  image{
    width: 100%;
    height: 100%;
  }
}
.nav-list{
  display: flex;
  justify-content: space-around;
  margin:15px 0px;
  .nav-image {
    width: 120rpx;
    height: 140rpx;
  }
}

 .foor-image{
    width: 100%;
    height: 60rpx;
    display: flex;
  }
  
  .foor-right-box{
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
  }
  .foor-box{
    display: flex;
    padding: 15rpx;
  }
  .search-box{
    position: sticky;
    top: 0px;
    z-index: 999px;
  }
</style>
